#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#endregion

namespace SpaceGame
{
    /// <summary>
    /// The pause menu comes up over the top of the game,
    /// giving the player options to resume or quit.
    /// </summary>
    /// <remarks>
    /// This class is somewhat similar to one of the same name in the 
    /// GameStateManagement sample.
    /// </remarks>
    class PauseMenuScreen : PhoneMenuScreen
    {
        
        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        public PauseMenuScreen() : base (StringData.pause_text)
        {
			//MenuEntry resumeGameMenuEntry = new MenuEntry("Resume Game");
			//MenuEntry quitGameEntry = new MenuEntry("Quit Game");

			Button resumeGameButton = new Button(StringData.resume_game_text);
			resumeGameButton.Tapped += new EventHandler<EventArgs>(resumeGameButton_Tapped);
			Button endGameButton = new Button(StringData.end_game_text);
			endGameButton.Tapped += new EventHandler<EventArgs>(endGameButton_Tapped);

			MenuButtons.Add(resumeGameButton);
			MenuButtons.Add(endGameButton);

			//resumeGameMenuEntry.Selected += ResumeGameMenuEntrySelected;
			//quitGameEntry.Selected += QuitGameEntrySelected;

			//MenuEntries.Add(resumeGameMenuEntry);
			//MenuEntries.Add(quitGameEntry);

            // Flag that there is no need for the game to transition
            // off when the pause menu is on top of it.
            IsPopup = true;
        }

		void endGameButton_Tapped(object sender, EventArgs e)
		{
			LoadingScreen.Load(ScreenManager, LoadMainMenuScreen, false);
		}

		void resumeGameButton_Tapped(object sender, EventArgs e)
		{
			ExitScreen();
		}

 
        #endregion

        #region Handle Input


        /// <summary>
        /// When the user cancels the pause menu, resume the game.
        /// </summary>
        protected override void OnCancel()
        {
            ExitScreen();
        }


        /// <summary>
        /// Event handler for when the Resume Game menu entry is selected.
        /// </summary>
		//void ResumeGameMenuEntrySelected(object sender, EventArgs e)
		//{
		//    ExitScreen();
		//}


        /// <summary>
        /// Event handler for when the Quit Game menu entry is selected.
        /// </summary>
        void QuitGameEntrySelected(object sender, EventArgs e)
        {
            // Quit the game, after a confirmation message box.
            const string message = "Are you sure?";

            MessageBoxScreen messageBox = new MessageBoxScreen(message);
            messageBox.Accepted += QuitMessageBoxAccepted;
            ScreenManager.AddScreen(messageBox);
        }


        /// <summary>
        /// Event handler for when the user selects ok on the "are you sure
        /// you want to quit" message box. This uses the loading screen to
        /// transition from the game back to the main menu screen.
        /// </summary>
        void QuitMessageBoxAccepted(object sender, EventArgs e)
        {
            LoadingScreen.Load(ScreenManager, LoadMainMenuScreen, false);
        }


        /// <summary>
        /// Loading screen callback for activating the main menu screen,
        /// used when quitting from the game.
        /// </summary>
        void LoadMainMenuScreen(object sender, EventArgs e)
        {
            //ScreenManager.AddScreen(new BackgroundScreen());
            ScreenManager.AddScreen(new PhoneMainMenuScreen());
        }

        #endregion

        #region Draw


        /// <summary>
        /// Draws the pause menu screen. This darkens down the gameplay screen
        /// that is underneath us, and then chains to the base MenuScreen.Draw.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);
            
            base.Draw(gameTime);
        }


        #endregion
    }
}
